# 回合制对战游戏
# • 创建角色：名字、性别、血量、装备
#     • 装备-防弹衣
#     • 血量默认100
#     • 正常被攻击-10滴血
#     • 有防弹衣-5滴血
# • 创建房间：
#     • 角色可加入房间
#     • 房间内的人可互打
#     • 房间上限2人
#     • 战斗
import time#导入时间的包
import random
class Role:
    number = 0
    def __init__(self,name,sex,hp,equipment):
        self.name = name
        self.sex = sex
        self.hp = hp
        self.equipment = equipment
        Role.number += 1

    def tong(self,enemy):
        num1 = random.randint(0, 5)
        if self.equipment is None:
            enemy.hp-=(num1 * 10)
        else:
            enemy.hp-=(num1 * 5)

        info='%s捅了%s一刀'%(self.name, enemy.name)
        print (info)

    def kanren(self,enemy):
        num2 = random.randint(0, 5)
        if self.equipment is None:
            enemy.hp -= (num2 * 8)
        else:
            enemy.hp -= (num2 * 4)
        info = '%s砍了%s一刀' % (self.name, enemy.name)
        print (info)


    def __str__(self):
        return  '%s 还剩下 %s 的血量'%(self.name,self.hp)

# 进入房间的玩家数目
class Room():
    def Enter_room():
        if Role.number == 1:
            print("第一位玩家进入成功，等待另一位玩家的进入..")
        if Role.number == 2:
            print("两位玩家以成功进入房间，请准备开始战斗！")
        else:
            print("游戏人数不符合游戏设定，游戏进行失败..")
#创建两个小李,小文,实例化对象

li=Role('小李',"M",100,"None")
wen=Role('小文',"W",100,"clothes")
room = Room
room.Enter_room()
while True:
    if li.hp<=0 or wen.hp<=0:
        if li.hp>0:
            print("小李获胜")
        else:
            print("小文获胜")
        #满足条件,退出循环;
        break
    num1 = random.randint(0,1)
    if num1 == 0:
        li.tong(wen)#小李捅小文
    else:
        li.kanren(wen)
    print(wen)#打印对象状态
    print(li)
    print ('***********************')
    num1 = random.randint(0,1)
    if num1 == 0:
        wen.tong(li)#小李捅小文
    else:
        wen.kanren(li)
    print(wen)#打印对象状态
    print(li)
    print('************************')
    time.sleep(1)#循环一次暂停时间一秒

print ('对战结束')

# import random
# class Person():
#     def __init__(self,name,sex,blood=100):
#         self.name=name
#         self.sex=sex
#         self.blood=blood
#     def attach(self,other):
#         if self==other:
#             print("不能攻击自己")
#         else:
#             if self.room ==other.room:
#                 if self.blood<=0:
#                     print("您的血量低于0，已死亡！")
#                 else:
#                     if random.choice([0,1])==0:
#                         lost_blood=10
#                         print(f"{other.name}没有使用装备")
#                     else:
#                         lost_blood=5
#                         print(f"{other.name}使用了装备")
#                     other.blood=other.blood-lost_blood
#                     print(f"{self.name}攻击了{other.name}")
#                     if other.blood<=0:
#                         print(f"{other.name}已阵亡，结束战斗！")
#                         exit()
#
#             else:
#                 print("不在一个房间不能相互攻击")
#
#
#
#
#
# class Room():
#     def __init__(self,name):
#         self.name=name
#         self.member_list=[]
#     def add_member(self,person):
#         if person.room==None:
#             if len(self.member_list)<2:
#                 self.member_list.append(person)
#                 person.room=self
#                 print(f"{person.name}成功加入{self.name}房间")
#         else:
#             print(f"{person.name}已加入{person.room.name}房间")
# person=dict()
# rooms=dict()
# while True:
#     str1=input("请输入你要进行的操作：")
#     if str1.isdigit():
#         str1=int(str1)
#         if 1<=str1<=5:
#             if str1==1:
#                 name=input("请输入用户名")
#                 sex=input("请输入性别")
#                 person[name,sex]=Person(name,sex)
#             elif str1==2:
#                 room=input("请输入房间号")
#                 rooms[room]=Room(room)
#             elif str1==3:
#                 print(f"当前角色有{person.keys()},当前房间有{rooms.keys()}")
#                 person_name=input("请输入您要加入的角色")
#                 rooms_name=input("请输入您要加入的房间号")
#                 rooms[rooms_name].add_member(person[person_name])
#             elif str == 4:
#                 while True:
#                     enter = random.choice([0, 1])
#                     if enter == 0:
#                         rooms[rooms_name].member_list[0].attach(rooms[rooms_name].member_list[1])
#             else:
#                         rooms[rooms_name].member_list[1].attach(rooms[rooms_name].member_list[0])
#         else:
#                 print("输入错误！请输入1-5选择操作！")
#     else:
#             print("输入有误！请重新输入！")
